jingheMgr = {}
QMPlugin = jingheMgr
jingheMgr.mode = 0
function jingheMgr.init()
    if boot.platform == 1 then
        jingheMgr.paraConfig = {
            ["锦盒"] = {  170,1104,354,1359,"3D88C1-303030","20|-11|FAFAFA,17|14|F7F7F7,-12|-12|C3B1AE,-16|13|CCBBB3,-11|43|8E6D66,16|39|947572,5|41|557ED1,11|53|5B7CCF,-17|54|567BD0",0,0.9},
            ["侧边栏"] = { 41,75,904,462,"6597DB-303030","19|-51|182971,16|-64|182971,-5|-62|182971,-9|-49|182971,16|-31|182971,-10|-19|182971,-10|5|182971,-5|61|192B73,-9|65|1E3179",0,0.9},
            ["梦幻币"] = {182,471,905,1761,"2DA3E8-303030","25|-3|EEFFFF,22|-14|93E6FB,-9|-18|33AAEE,-8|12|36A4EB,5|12|32A6E8,13|6|98F0FE,12|-8|71E8FF,-4|-13|3AC2FF,-8|-2|3BBDFF",0,0.95},
            ["购买"] = { 179,1392,278,1689,"4D56D7-303030","9|-69|515CDB,4|80|4E59D7,22|-22|D0EEFF,20|-40|D0EEFF,-1|-41|CFEEFF,-10|-41|CFEEFF,-10|-29|CFEEFF,-9|-20|CFEEFF,-10|21|CFEEFF",0,0.9},
        }
    else
    end
end

function jingheMgr.setMode(mode)
    jingheMgr.mode = mode
end

local function findIcon()
    local para = jingheMgr.paraConfig["梦幻币"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

local function jinhe()
    local para = jingheMgr.paraConfig["锦盒"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

local function cebianlan()
    local para = jingheMgr.paraConfig["侧边栏"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end


local function buy()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = jingheMgr.paraConfig["购买"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end

local function buyNow()
    local para = jingheMgr.paraConfig["购买"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

function jingheMgr.execTask()
    mlog.info("锦盒")
    local count = 1
    while true do
        local cebianlanBtn,x,y = cebianlan()
        if cebianlanBtn then
            game.tap(x, y)
            game.delay(500)
            local jinheBtn,x,y = jinhe()
            if jinheBtn then
                game.tap(x, y)
                game.delay(500)
                local findIconBtn,x,y = findIcon()
                while findIconBtn do
                    game.tap(x, y)
                    game.delay(500)
                    local buy,x,y = findIcon()
                    if buy then
                        game.tap(x, y)
                        game.delay(300)
                    end
                    findIconBtn,x,y = findIcon()
                end
            end
        end
    end
end